﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace FoodFight3D
{
    public class Kathy : Game1
    {
        //constants
        const float rotationSpeed = .04f;
        const float moveSpeed = .2f;
        
        public Model KathyModel;
        public int Strength;
        //public food[] FoodsHeld;
        public Vector3 location;
        public float rotationAngle;
        public Vector3 velocity;
        KeyboardState keyboardState = Keyboard.GetState();
        public bool holdingFood = false;
        public int heldNum;
        
        bool access = true;


        public Kathy(Model model, float x, float y, float z)
        {
            KathyModel = model;
            Strength = 80;
            //location = new Vector3(-45f, 0.1f, 45f);
            location = new Vector3(x, y, z);
            velocity = new Vector3(0.0f, 0.0f, 0.0f);
            rotationAngle = 2.35f;
            audioEngine = new AudioEngine("Content/mySound.xgs");
            waveBank = new WaveBank(audioEngine, "Content/Wave Bank.xwb");
            soundBank = new SoundBank(audioEngine, "Content/Sound Bank.xsb");
            //foodsheld
        }
       
            
            
       /* 

        public Kathy()
        {
            Strength = 100;
            location = new Vector3(0.0f, 0.0f, 0.0f);
            velocity = new Vector3(0.0f, 0.0f, 0.0f);
            rotationAngle = 2.35f;


            
        }*/

        public void reset()
        {
            if (milliseconds < 200)
                access = true;
        }

        public void move()
        {
            KeyboardState keyboardState = Keyboard.GetState();

            if (keyboardState.IsKeyDown(Keys.W))
            {
                location += Vector3.Transform(new Vector3(-moveSpeed, 0f, 0f), Matrix.CreateRotationY(MathHelper.ToRadians(90) + rotationAngle));
                
                if (location.X > 50)
                    location.X = 50;
                if (location.Z > 50)
                    location.Z = 50;
                if (location.X < -50)
                    location.X = -50;
                if (location.Z < -50)
                    location.Z = -50;

                if (access)
                {
                    soundBank.PlayCue("Footsteps");
                    access = false;
                    
                }
                if (milliseconds == 400)
                    access = true;
            }

            if (keyboardState.IsKeyDown(Keys.A))
            {
                
                rotationAngle += rotationSpeed;
                if (access)
                {
                    soundBank.PlayCue("Footsteps");
                    access = false;

                }
                if (milliseconds == 400)
                    access = true;
            }

            if (keyboardState.IsKeyDown(Keys.S))
            {

                location += Vector3.Transform(new Vector3(moveSpeed, 0f, 0f), Matrix.CreateRotationY(MathHelper.ToRadians(90) + rotationAngle));
                if (location.X > 50)
                    location.X = 50;
                if (location.Z > 50)
                    location.Z = 50;
                if (location.X < -50)
                    location.X = -50;
                if (location.Z < -50)
                    location.Z = -50;

                if (access)
                {
                    soundBank.PlayCue("Footsteps");
                    access = false;

                }
                if (milliseconds == 400)
                    access = true;
            }

            if (keyboardState.IsKeyDown(Keys.D))
            {
                // location = new Vector3(0f, 0f, 50f);
                rotationAngle -= rotationSpeed;
                if (access)
                {
                    soundBank.PlayCue("Footsteps");
                    access = false;

                }
                if (milliseconds == 400)
                    access = true;
            }

            if (keyboardState.IsKeyDown(Keys.E))
            {

                location += Vector3.Transform(new Vector3(0f, 0f, -moveSpeed), Matrix.CreateRotationY(MathHelper.ToRadians(90) + rotationAngle));
                if (location.X > 50)
                    location.X = 50;
                if (location.Z > 50)
                    location.Z = 50;
                if (location.X < -50)
                    location.X = -50;
                if (location.Z < -50)
                    location.Z = -50;

                if (access)
                {
                    soundBank.PlayCue("Footsteps");
                    access = false;

                }
                if (milliseconds == 400)
                    access = true;
            }

            if (keyboardState.IsKeyDown(Keys.Q))
            {

                location += Vector3.Transform(new Vector3(0f, 0f, moveSpeed), Matrix.CreateRotationY(MathHelper.ToRadians(90) + rotationAngle));
                if (location.X > 50)
                    location.X = 50;
                if (location.Z > 50)
                    location.Z = 50;
                if (location.X < -50)
                    location.X = -50;
                if (location.Z < -50)
                    location.Z = -50;

                if (access)
                {
                    soundBank.PlayCue("Footsteps");
                    access = false;

                }
                if (milliseconds == 400)
                    access = true;
            }
     
        }

        public void throwFood()
        {
        }

        public void draw(Matrix world, Matrix view, Matrix projection)
        {
            for (int index = 0; index < KathyModel.Meshes.Count; index++)
            {
                ModelMesh mesh = KathyModel.Meshes[index];
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.PreferPerPixelLighting = true;
                    effect.EnableDefaultLighting();
                    effect.World = mesh.ParentBone.Transform * world;
                    effect.View = view;
                    effect.Projection = projection;
                }

                mesh.Draw();
            }
        
        }





    }
}
